{% extends 'layout/base.html' %}

{% block content %}
<div class="row mt-5">
    <div class="col-lg-3">
        {% set active_nav = 'ldap' %}
        {% include 'config/includes/sidebar.html' %}
    </div>
    <div class="col-lg-5">
        <h4>LDAP Authentication</h4>
        <form action="{{ url_for('config.ldap_save') }}" method="post">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

            <h5>Connection</h5>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_enabled">Enable LDAP Auth</label>
                </div>
                <div class="col text-right">
                    <div class="custom-control custom-switch">
                        <input name="ldap_enabled" type="checkbox" class="custom-control-input" id="ldap_enabled" value="1" {{ 'checked' if setting_get('ldap_enabled', False) == True }}>
                        <label class="custom-control-label" for="ldap_enabled"></label>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_ssl">SSL</label>
                </div>
                <div class="col text-right">
                    <div class="custom-control custom-switch">
                        <input name="ldap_ssl" type="checkbox" class="custom-control-input" id="ldap_ssl" value="1" {{ 'checked' if setting_get('ldap_ssl', False) == True }}>
                        <label class="custom-control-label" for="ldap_ssl"></label>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_host">Host</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="ldap_host" id="ldap_host" value="{{ setting_get('ldap_host', '') }}" placeholder="">
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_base_dn">Base DN</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="ldap_base_dn" id="ldap_base_dn" value="{{ setting_get('ldap_base_dn', '') }}" placeholder="dc=example,dc=com">
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_domain">Domain</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="ldap_domain" id="ldap_domain" value="{{ setting_get('ldap_domain', '') }}" placeholder="EXAMPLE">
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_bind_user">Bind Username</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="ldap_bind_user" id="ldap_bind_user" value="{{ setting_get('ldap_bind_user', '') }}" placeholder="readonlyuser">
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_bind_pass">Bind Password</label>
                </div>
                <div class="col">
                    <input type="password" class="form-control text-right" name="ldap_bind_pass" id="ldap_bind_pass" value="{{ '********' if setting_get('ldap_bind_pass', '')|length > 0 }}" placeholder="readonlypass">
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_pwchange">
                        Allow Password Updates
                        <a href="#" title="" data-container="body" data-toggle="popover" data-placement="right" data-content="If the Bind User has write privileges, you can enable the LDAP Password change feature when the credentials have expired or for manual update by users.<br><br>In order for this feature to work, the SSL has to be enabled for the LDAP integration." data-original-title="LDAP Password Updates"><i class="fas fa-question-circle ml-1"></i></a>
                    </label>
                </div>
                <div class="col text-right">
                    <div class="custom-control custom-switch">
                        <input name="ldap_pwchange" type="checkbox" class="custom-control-input" id="ldap_pwchange" value="1" {{ 'checked' if setting_get('ldap_pwchange', False) == True }}>
                        <label class="custom-control-label" for="ldap_pwchange"></label>
                    </div>
                </div>
            </div>

            <h5>Mappings</h5>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_mapping_username">Username</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="ldap_mapping_username" id="ldap_mapping_username" value="{{ setting_get('ldap_mapping_username', '') }}" placeholder="sAMAccountName">
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_mapping_fullname">Full Name</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="ldap_mapping_fullname" id="ldap_mapping_fullname" value="{{ setting_get('ldap_mapping_fullname', '') }}" placeholder="givenName">
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="ldap_mapping_email">E-mail</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="ldap_mapping_email" id="ldap_mapping_email" value="{{ setting_get('ldap_mapping_email', '') }}" placeholder="mail">
                </div>
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-block btn-primary">save</button>
            </div>
        </form>

        <h4>Test Connection</h4>

        <form action="{{ url_for('config.ldap_test') }}" method="post" class="pb-2">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

            <div class="form-group">
                <button type="submit" class="btn btn-block btn-primary">test connection</button>
            </div>
        </form>
    </div>
    <div class="col"></div>
</div>
{% endblock %}